<?php
/**
 * Application level View Helper
 *
 * This file is application-wide helper file. You can put all
 * application-wide helper-related methods here.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.View.Helper
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

App::uses('Helper', 'View');

/**
 * Application helper
 *
 * Add your application-wide methods in the class below, your helpers
 * will inherit them.
 *
 * @package       app.View.Helper
 */
class AppHelper extends Helper {
	
	public $helpers = array('Form', 'Session', 'Html');
	
	public function datepicker($name, $value='') {
		return $this->Form->text($name, array(
			'class' => 'datepicker',
			'value' => $value,
			'maxlength' => 10
		));
	}
	
	public function ruleArgument($name, $type, $options) {
	    switch ($type) {
	    	case 'int':
	    	    $options = array_merge(array(
                    'div'   => false,
                    'style' => 'width:30px'
	    	    ),$options);
	    	    $ret = $this->Form->input($name, $options);
	    	    break;
	    	
	    	case 'year':
	    	    $selOptions = array();
	    	    $now = (int)date('Y');
	    	    for ($i=$now-10; $i<$now+10; $i++) {
	    	        $selOptions[$i] = $i;
	    	    }
	    	case 'month':
	    	    if (empty($selOptions)) {
    	    	    $selOptions = array(
    	    	    	1  => 'January',
    	    	    	2  => 'February',
    	    	    	3  => 'March',
    	    	    	4  => 'April',
    	    	    	5  => 'May',
    	    	    	6  => 'June',
    	    	    	7  => 'July',
    	    	    	8  => 'August',
    	    	    	9  => 'September',
    	    	    	10 => 'October',
    	    	    	11 => 'November',
    	    	    	12 => 'December'
    	    	    );
	    	    }
	    	    $options = array_merge(array(
                    'empty' => false
	    	    ),$options);
	    	    $ret = $this->Form->label($name, $options['label']).
	    	           $this->Form->select($name, $selOptions, $options);
	    	    break;
	        
	        default:
	            $options = array_merge(array(
	            	'div' => false
	            ),$options);
	            $ret = $this->Form->input($name, $options);
	    }
	    
	    return $ret;
	}
	
	public function approveControl($leaveId) {
	    $role = $this->Session->read('Auth.User.role');
	    
	    $ret = '?';
	    if ($role == 'admin') {
	        $ret = $this->Html->link('approve', array(
	        	'controller' => 'leaves',
                'action'     => 'approve',
                $leaveId
	        ), array('class'=>'ok')) . ' | '. $this->Html->link('disapprove', array(
	        	'controller' => 'leaves',
                'action'     => 'disapprove',
                $leaveId
	        ), array('class'=>'error'));
	    }
	    
	    return $ret;
	}
	
}
